package com.lablzh.gdxy.repository.course;

import com.lablzh.gdxy.entity.course.Course;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface CourseRepository extends JpaRepository<Course,Integer> {
 List<Course> findAllByTeacherUsername(String username, Sort sort);

 List<Course> findAllByResTeacherUserName(String username, Sort sort);
 List<Course> findAllByTeacherUsernameOrResTeacherUserName(String username,String username1, Sort sort);


 Course findByCourseName(String courseName);
 @Modifying
 @Transactional
 @Query("update Course set toReview=?2, reviewed=?3 where id=?1")
 void updateToReviewAndReviewedById(Integer id, int toReview,int reviewed );


 List<Course> findAllByCategoryAndGrade(String category, String grade);
 @Modifying
 @Transactional
 @Query("update Course set toSummit=?2,summited=?3, toReview=?4 where id=?1")
 void updateToSummitAndSummitedAndToReviewById(Integer id, int toSummit, int summited, int toReview);
 @Modifying
 @Transactional
 @Query("update Course set applyed=?2 where id=?1")
 void updateApplyedById(Integer id, int i);
 List<Course> findAllByCollegeAndGrade(String college, String grade);
}
